package com.treasure.service.commission.controller.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.treasure.service.commission.service.CommissionService;
import com.treasure.service.domain.TGainTtatistics;
import com.treasure.service.mapper.TGainTtatisticsMapper;
import com.treasure.service.util.DateUtil;
import com.treasure.service.util.NumberUtil;

import lombok.extern.slf4j.Slf4j;

/**
* @Description:    Todo 客户佣金管理
* @Author:         panxinwen
* @CreateDate:     2018/11/17 15:44
* @Version:        1.0
*/
@Service
@Slf4j
public class CommissionServiceImpl implements CommissionService {
	@Autowired
    private TGainTtatisticsMapper tGainTtatisticsMapper;

    @Override
    public Map<String, Object> getStatistics(Long userId) {
    	Long currentWeekStartDate = Long.valueOf(DateUtil.getCurrWeekStartDate(DateUtil.DATE_SMALL_DD));
    	Long currentDate = Long.valueOf(DateUtil.formateDate(new Date(),DateUtil.DATE_SMALL_DD));
    	log.info("查询统计需求:userId="+userId+"startDate="+currentWeekStartDate+",endDate="+currentDate);
    	TGainTtatistics thisWeekcount = tGainTtatisticsMapper.getMyStatistics(userId,currentWeekStartDate,currentDate);
    	log.info("查询本周收益结果:"+JSON.toJSONString(thisWeekcount));
    	TGainTtatistics totalcount = tGainTtatisticsMapper.getMyTotalStatistics(userId);
    	log.info("查询总收益结果:"+JSON.toJSONString(totalcount));

        Map<String,Object> map = new HashMap<>();
        if(thisWeekcount==null||thisWeekcount.getAmount()==null) {
        	map.put("weekAmount","0.00");
        }else {
        	map.put("weekAmount",NumberUtil.div(thisWeekcount.getAmount(), 100, 2));
        }
        
        if(totalcount==null || totalcount.getAmount()==null) {
        	map.put("totalAmount","0.00");
        }else {
        	map.put("totalAmount",NumberUtil.div(totalcount.getAmount(), 100, 2));
        }
        return map;
    }
}
